package controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import pojo.Book;
import service.BookManager;

@Controller
public class BookController {
	@Autowired
	private BookManager bm;
	
	@RequestMapping("/addBook")
	public String addBook(Book b){
		bm.addBook(b);
		
		return "redirect:/findAllBooks";
	}
	@RequestMapping("/findAllBooks")
	public String findAllBooks(Model model){
		List<Book> books=bm.findAllBooks();
		model.addAttribute("books",books);
		return "bookList";
	}
	@RequestMapping("/deleteBook")
	public String deleteBook(int id){
		bm.deleteBook(id);
		return "redirect:/findAllBooks";
	}

}
